﻿   var From="";
   var BookAccessionId="";
   var BookTitle="";
   var BookAccessionNo="";
   var Author="";
   var PublicationName="";
   var Edition="";
   function ShowAddress(BuldingName,FloorName,RoomName)
	{
     if(document.getElementById("Address"))
	   {
	      document.getElementById("Address").value=BuldingName+" >> "+FloorName+" >> "+RoomName;
	   }
	}
   function showADetail(almirahName,sectionCount)
   {
	    var detailDiv=document.getElementById("detailContentDiv");
	   detailDiv.innerHTML="<table cellpading='5' cellspapcing='0' width='100%' border='0' ><tr><td align='left' width='60%' >Almirah Name : </td><td align='left' width='40%'>"+almirahName+"</td></tr><tr><td align='left' width='60%'>Total Section : </td><td align='left' width='40%'>"+sectionCount+"</td></tr></table>";
   }
   function showAAddress(almirahName)
   {
	    document.getElementById('Address').value+=">>"+almirahName;
   }
   function showSDetail(sectionName,bookCount)
   {
	    var detailDiv=document.getElementById('detailContentDiv');
		detailDiv.innerHTML="<table cellpading='5' cellspapcing='0' width='100%' border='0' ><tr><td align='left' width='60%' >Section Name : </td><td align='left' width='40%'>"+sectionName+"</td></tr><tr><td align='left' width='60%'>Total Books : </td><td align='left' width='40%'>"+bookCount+"</td></tr></table>"
   }
   function showSAddress(sectionName)
   {
	    document.getElementById('Address').value+=">>"+sectionName;
   }
   function showBDetail(bookName,authorName,publicationName,edition)
   {
	    var detailDiv=document.getElementById('detailContentDiv');
		detailDiv.innerHTML="<table cellpading='5' cellspapcing='0' width='100%' border='0' ><tr><td align='left' width='60%' >Book Name : </td><td align='left' width='40%'>"+bookName+"</td></tr><tr><td align='left' width='60%'>Author Name : </td><td align='left' width='40%'>"+authorName+"</td></tr><tr><td align='left' width='60%'>Publication Name : </td><td align='left' width='40%'>"+publicationName+"</td></tr><tr><td align='left' width='60%'>Edition : </td><td align='left' width='40%'>"+edition+"</td></tr></table>"
   }
   
   function getRowId(_sourceId,_tableId,event)
   {
      
	   if(document.getElementById(_sourceId))
	    {  
          stopDefault(event);
		 document.getElementById(_tableId).style.cursor='default';
       	 var _checkId='checkBook'+(_sourceId.substring(7,_sourceId.length));
		 if (document.getElementById(_checkId))
		 {
		 document.getElementById(_checkId).checked=true;
		 }
         RowId="";
         TableId=_tableId
        
		 var _checkboxBook=document.getElementsByName('checkBook');
		 var _bookAccessionId=document.getElementsByName('BookAccessionId');
		 var _bookTitle=document.getElementsByName('BookTitle');
		 var _bookAccessionNo=document.getElementsByName('DragBookAccessionNo');
		 var _author=document.getElementsByName('Author');
		 var _publicationName=document.getElementsByName('PublicationName');
		 var _edition=document.getElementsByName('Edition');
		 BookAccessionId="";
		 BookTitle="";
		 BookAccessionNo="";
		 Author="";
		 PublicationName="";
		 Edition="";
		 var _temp="";
		 for (var i=0;i<_checkboxBook.length;i++)
		 {	
			 if(_checkboxBook[i].checked==true)
			 {   
				BookAccessionId+=_bookAccessionId[i].value+"|";
				BookTitle+=_bookTitle[i].value+"|";
				BookAccessionNo+=_bookAccessionNo[i].value+"|";
				Author+=_author[i].value+"|";
				PublicationName+=_publicationName[i].value+"|";
				Edition+=_edition[i].value+"|";
			   _temp+='<tr><td>'+_bookTitle[i].value+'</td><td>'+_bookAccessionNo[i].value+'</td><td>'+_author[i].value+'</td><td>'+_publicationName[i].value+'</td><td>'+_edition[i].value+'</td></tr>';
			 }
		 }
		 var _checkBook=document.getElementById("Book").getElementsByTagName('input');
		 var div=document.createElement("div");
         div.id="moving";
         div.style.position='absolute';
         div.style.left=""+X+"px";
         div.style.top=""+Y+"px";
         div.style.cursor="move";
		 div.innerHTML="<table class='tblist' width='300px' cellpadding='0' cellspacing='0'border='1' >"+_temp+"</table>";
		 document.body.appendChild(div);
		 From='Drag';
		 document.onmouseup=mouseUpEve;
		 }
   }
   function findPos(obj)
   {
	    var _topX=_bottomX=_leftY=_rightY=_height=_width=0;
		 if(document.getElementById(obj))
		 {
			 var _element=document.getElementById(obj);
			 _height=_element.offsetHeight;
			 _width= _element.offsetWidth;
			 while(_element)
			 {
				_topX+=_element.offsetLeft;
				_leftY+= _element.offsetTop;
				_element=_element.offsetParent;
			 }
			 _topX=_topX-parseInt(document.getElementById('Almirah').scrollLeft);
			 _leftY=_leftY-parseInt(document.getElementById('Almirah').scrollTop);
			_rightY=parseInt(_leftY)+parseInt(_height);
			_bottomX=parseInt(_topX)+parseInt(_width);
		    return{curX:_topX,LastX:_bottomX,curY:_leftY,LastY:_rightY}
		  }
		  else
		  {
		     return{curX:_topX,LastX:_bottomX,curY:_leftY,LastY:_rightY}
		  }
   }
   function mouseUpEve() /* Code For Drop The Item */
   {
      startSelectTable="";
	  var table=document.getElementsByTagName('table');
      var pos;
      var dropId="";
	    if(From=='Drag') /*Code For Unallocated Books For Drop */
	     {
		  for(var i=0;i<table.length;i++)
		 {   
		   
			 if(table[i].getAttribute("name")=="SectionBookDrop")
			 {
				  pos=findPos(table[i].id);
				  dropId=table[i].id;
				   if ((X>=pos.curX && X<=pos.LastX) && (Y>=pos.curY && Y<=pos.LastY))
				  {
				  senddata('BookLocationLinking','T=BookLocationLinking_Save&Status=U&BookAccessionId='+BookAccessionId+'&BuildingId='+document.getElementById('DropBuildingId').value+'&FloorId='+document.getElementById('DropFloorId').value+'&RoomId='+document.getElementById('DropRoomId').value+'&AlmirahId='+document.getElementById('AlmirahId').value+'&sectionId='+getValueofDropItem(dropId,'SectionId').substring(0,getValueofDropItem(dropId,'SectionId').length-1)+'&searchtype='+document.getElementById('searchType').value+'&val='+document.getElementById('val').value,'searchDiv');
					break;
				  }
			 }
			  if(table[i].getAttribute("name")=="BookDrop")
			    {
					
				  pos=findPos(table[i].id);
				  //dropId=table[i].id;
				   if ((X>=pos.curX && X<=pos.LastX) && (Y>=pos.curY && Y<=pos.LastY))
					{
					  removeChildByName('moving');
					  var BookTitleArray=new Array()
					  var BookAccessionNoArray=new Array()
					  var AuthorArray=new Array()
					  var PublicationNameArray=new Array()
					  var EditionArray=new Array()
					  BookAccessionIdArray=BookAccessionId.split("|")
					  BookTitleArray=BookTitle.split("|");
					  BookAccessionNoArray=BookAccessionNo.split("|");
					  AuthorArray=Author.split("|");
					  PublicationNameArray=PublicationName.split("|");
					  EditionArray=Edition.split("|");
					  for(var i=0;i<BookTitleArray.length-1;i++)
					  {
						  var _length=document.getElementById("InBookDrop").getElementsByTagName('img').length+1;
						  var  _row=document.getElementById("InBookDrop").rows.length
						  var _Rows=document.getElementById("InBookDrop").rows[_row-1].cells.length;
						  if(_Rows<5)
						  {
							   var _td=document.getElementById("InBookDrop").rows[_row-1].insertCell(_Rows);
							  _td.innerHTML="<table id='tablenotwanted"+_length+"' name='tablenotwanted' title='"+BookAccessionIdArray[i]+","+BookTitleArray[i]+","+BookAccessionNoArray[i]+","+AuthorArray[i]+","+PublicationNameArray[i]+","+EditionArray[i]+"' cellpadding='0' cellspacing='2' class='icon' border='0'><tr><td align='center' ><div><img src='img/Book-icon.png' onmousedown=\"stopDefault(event);stopParentDefault(event);getItem('tablenotwanted"+_length+"','tablenotwanted',event,'"+BookAccessionIdArray[i]+"','"+BookTitleArray[i]+"','"+BookAccessionNoArray[i]+"','"+AuthorArray[i]+"','"+PublicationNameArray[i]+"','"+EditionArray[i]+"')\" onmouseover=\"showBDetail('"+BookTitleArray[i]+"-("+BookAccessionNoArray[i]+")','"+AuthorArray[i]+"','"+PublicationNameArray[i]+"','"+EditionArray[i]+"')\"  alt='' /></div><a href='#'  onmousedown=\"stopDefault(event);stopParentDefault(event);getItem('tablenotwanted"+_length+"','tablenotwanted',event,'"+BookAccessionIdArray[i]+"','"+BookTitleArray[i]+"-("+BookAccessionNoArray[i]+")','"+AuthorArray[i]+"','"+PublicationNameArray[i]+"','"+EditionArray[i]+"')\" onmouseover=\"showBDetail('"+BookTitleArray[i]+"-("+BookAccessionNoArray[i]+")','"+AuthorArray[i]+"','"+PublicationNameArray[i]+"','"+EditionArray[i]+"')\" >"+BookTitleArray[i]+"-("+BookAccessionNoArray[i]+")</a></td></tr></table>";
						 }
						  else
						  {
							 var _insRow=document.getElementById("InBookDrop").insertRow(_row);
							 var x=new Array();
							 x[0]=_insRow.insertCell(0);
							 x[0].innerHTML="<table id='tablenotwanted"+_length+"' name='tablenotwanted' title='"+BookAccessionIdArray[i]+","+BookTitleArray[i]+","+BookAccessionNoArray[i]+","+AuthorArray[i]+","+PublicationNameArray[i]+","+EditionArray[i]+"' cellpadding='0' cellspacing='2' class='icon' border='0'><tr><td align='center' ><div><img src='img/Book-icon.png'  onmousedown=\"stopDefault(event);stopParentDefault(event);getItem('tablenotwanted"+_length+"','tablenotwanted',event,'"+BookAccessionIdArray[i]+"','"+BookTitleArray[i]+"','"+BookAccessionNoArray[i]+")','"+AuthorArray[i]+"','"+PublicationNameArray[i]+"','"+EditionArray[i]+"')\" onmouseover=\"showBDetail('"+BookTitleArray[i]+"-("+BookAccessionNoArray[i]+")','"+AuthorArray[i]+"','"+PublicationNameArray[i]+"','"+EditionArray[i]+"')\" alt='' /></div><a href='#'  onmousedown=\"stopDefault(event);stopParentDefault(event);getItem('tablenotwanted"+_length+"','tablenotwanted',event,'"+BookAccessionIdArray[i]+"','"+BookTitleArray[i]+"-("+BookAccessionNoArray[i]+")','"+AuthorArray[i]+"','"+PublicationNameArray[i]+"','"+EditionArray[i]+"')\" onmouseover=\"showBDetail('"+BookTitleArray[i]+"-("+BookAccessionNoArray[i]+")','"+AuthorArray[i]+"','"+PublicationNameArray[i]+"','"+EditionArray[i]+"')\" >"+BookTitleArray[i]+"-("+BookAccessionNoArray[i]+")</a></td></tr></table>";
						 }
					  }
					 senddata('BookLocationLinking','T=BookLocationLinking_Save&Status=U&BookAccessionId='+BookAccessionId+'&BuildingId='+document.getElementById('DropBuildingId').value+'&FloorId='+document.getElementById('DropFloorId').value+'&RoomId='+document.getElementById('DropRoomId').value+'&AlmirahId='+document.getElementById('AlmirahId').value+'&sectionId='+document.getElementById('SectionId').value+'&searchtype='+document.getElementById('searchType').value+'&val='+document.getElementById('val').value,'searchDiv')
					 start=1;
				     From="";
   					 BookAccessionId="";
                     BookTitle="";
                     BookAccessionNo="";
                     Author="";
                     PublicationName="";
                     Edition="";
					break;
					}
			    }
		
			document.onmouseup="";
			removeChildByName('moving');
			RowId="";
			document.onmouseup="";
		  }
		 }
	  else   /* Code For Located Books For Drop */
	     {
		 if(BookAccessionId!="")
		 {
		 for(var i=0;i<table.length;i++)
		 {   
		    if(table[i].getAttribute("id")=="Book")
			 {
				   pos=findPos(table[i].id);
				  //dropId=table[i].id;
				   if ((X>=pos.curX && X<=pos.LastX) && (Y>=pos.curY && Y<=pos.LastY))
					{
						  removeChildByName('moving');
						  var BookAccessionIdArray=new Array()
						  var BookTitleArray=new Array()
						  var BookAccessionNoArray=new Array()
						  var AuthorArray=new Array()
						  var PublicationNameArray=new Array()
						  var EditionArray=new Array()
						  BookAccessionIdArray=BookAccessionId.split("|");
						  BookTitleArray=BookTitle.split("|");
						  BookAccessionNoArray=BookAccessionNo.split("|");
						  AuthorArray=Author.split("|");
						  PublicationNameArray=PublicationName.split("|");
						  EditionArray=Edition.split("|");
						  for (var i=0;i<BookAccessionIdArray.length-1;i++)
						  {
					        var where=0;
						    where = document.getElementById("Book").rows.length; 
							var td=document.getElementById("Book").rows[where-1].cells.length;
							if(td==1)
							{
								 //alert("Eneter");
								 document.getElementById("Book").deleteRow(where-1);
							}
							where = document.getElementById("Book").rows.length; 
                            var x=document.getElementById("Book").insertRow(where);
							x.id="bookrow"+where+"";
							x.setAttribute("onmousedown","stopDefault(event);getRowId(this.id,'Book',event);")
							x.setAttribute("onmouseover","cursor(this.id);")
					        var cl= new Array();
							cl[0]=x.insertCell(0);
							cl[1]=x.insertCell(1);
							cl[2]=x.insertCell(2);        
							cl[3]=x.insertCell(3);
							cl[4]=x.insertCell(4);
							cl[5]=x.insertCell(5);
							cl[6]=x.insertCell(6);
							cl[7]=x.insertCell(7);
							cl[0].innerHTML="<input type='checkbox' id='checkBook"+where+"' name='checkBook'/>";
							cl[1].innerHTML="<img src='img/Book-icon.png' alt='' height='20px' width='20px'  id='img"+where+"'/>";
							cl[2].innerHTML="<input type='hidden' name='BookTitle' id='BookTitle"+where+"' value='"+BookTitleArray[i]+"' />"+BookTitleArray[i];
							cl[3].innerHTML="<input type='hidden' id='Bookid"+where+"' name='Bookid' value='' /><input type='hidden' id='BookAccessionId"+where+"' name='BookAccessionId' value='"+BookAccessionIdArray[i]+"'/>";
							cl[4].innerHTML="<input type='hidden' name='DragBookAccessionNo' id='DragBookAccessionNo"+where+"' value='"+BookAccessionNoArray[i]+"' />"+BookAccessionNoArray[i];
							cl[5].innerHTML="<input type='hidden' name='Author' id='Author"+where+"' value='"+AuthorArray[i]+"' />"+AuthorArray[i];
							cl[6].innerHTML="<input type='hidden' name='PublicationName' id='PublicationName"+where+"' value='"+PublicationNameArray[i]+"' />"+PublicationNameArray[i];
							cl[7].innerHTML="<input type='hidden' name='Edition' id='Edition"+where+"' value='"+EditionArray[i]+"'/>"+EditionArray[i]
							
						  }
						  senddata('BookLocationLinking','T=BookLocationLinking_Save&Status=L&BookAccessionId='+BookAccessionId+'&BuildingId='+document.getElementById('DropBuildingId').value+'&FloorId='+document.getElementById('DropFloorId').value+'&RoomId='+document.getElementById('DropRoomId').value+'&AlmirahId='+document.getElementById('AlmirahId').value+'&sectionId='+document.getElementById('SectionId').value+'&searchtype=&val=','Explorer')
					   BookAccessionId="";
  					   BookTitle="";
  					   BookAccessionNo="";
  					   Author="";
 				       PublicationName="";
                       Edition="";
					   break;
					}
					else
					{
						 removeChildByName('moving');
					}
			 }
		 }
	    }
	  }
	  document.getElementById("checkAllDropedItem").checked=false;
	}
   function stopDefault(e) /* COde For Stop the Default Behavior of Button */
   {
	 if (e && e.preventDefault)
	 	{
			e.preventDefault();
		}
	else 
		{
			window.event.returnValue = false;
		}   
   }
    function removeChildByName(child)
   {
             var _body=document.body;
			 if(document.getElementById(child))
			 {
			 var _ele=document.getElementById(child);
			 _body.removeChild(_ele);
			 }
   }
  function SelectAll(id)
  {
        if(document.getElementById(id).checked==true)
        {
		    var _table=document.getElementsByTagName('table')
			for(var i=0;i<_table.length;i++)
			{
			  if(_table[i].getAttribute('name')=='tablenotwanted')
			  {
			     _table[i].className='iconselect';
			      var _tempArray=new Array();
			      _tempArray=_table[i].getAttribute('title').split(",");
			      BookAccessionId+=_tempArray[0]+"|";
			      BookTitle+=_tempArray[1]+"|";
			      BookAccessionNo+=_tempArray[2]+"|";
			      Author+=_tempArray[3]+"|";
			      PublicationName+=_tempArray[4]+"|";
			      Edition+=_tempArray[5]+"|";       
			  }
			}
			
		 }
		 else
		 {
		     var _table=document.getElementsByTagName('table')
			for(var i=0;i<_table.length;i++)
			{
			  if(_table[i].getAttribute('name')=='tablenotwanted')
			  {
			     _table[i].className='icon';
			      BookAccessionId+="";
			      BookTitle+="";
			      BookAccessionNo+="";
			      Author+="";
			      PublicationName+="";
			      Edition+="";       
			  }
			}
		 }
  }
   function cursor(id)
   {
	   document.getElementById(id).style.cursor='default';
   }

   function getItem(id,name,event,bookAccessionId,bookTitle,bookAccesionNo,author,publicationName,edition)
   {
    var unselect='';
     var _table=document.getElementsByTagName('table');
	 for(var i=0;i<_table.length;i++)
	  {
	     if(event.ctrlKey)    /* Code For get The Item with CTRL Button*/
		  {
			 if(document.getElementById(id).className=='iconselect' && (_table[i].getAttribute('id')==id))
			 {   
				  document.getElementById(id).className='icon';
				  var BookAccessionIdArray=new Array()
			      var BookTitleArray=new Array()
			      var BookAccessionNoArray=new Array()
			      var AuthorArray=new Array()
			      var PublicationNameArray=new Array()
			      var EditionArray=new Array()
			      BookAccessionIdArray=BookAccessionId.split("|");
			      BookTitleArray=BookTitle.split("|");
			      BookAccessionNoArray=BookAccessionNo.split("|");
			      AuthorArray=Author.split("|");
			      PublicationNameArray=PublicationName.split("|");
			      EditionArray=Edition.split("|");
			      if(BookAccessionIdArray.length>1)
			      {
			         BookAccessionId="";
   		             BookTitle="";
   	 	             BookAccessionNo="";
    	             Author="";
   		             PublicationName="";
  		             Edition="";
			          for(var i=0;i<BookAccessionIdArray.length-1;i++)
			          {
			              if(BookAccessionIdArray[i]!=bookAccessionId)
			              {
			                 BookAccessionId+=BookAccessionIdArray[i]+"|";
			                 BookTitle+=BookTitleArray[i]+"|";
			                 BookAccessionNo+=BookAccessionNoArray[i]+"|";
			                 Author+=AuthorArray[i]+"|";
			                 PublicationName+=PublicationNameArray[i]+"|";
			                 Edition+=EditionArray[i]+"|";  
			                 
			              }
			              else
			              {
			               unselect="unselect";
			              }
			          }
			      }
			      else
			      {
				     BookAccessionId="";
   		             BookTitle="";
   	 	             BookAccessionNo="";
    	             Author="";
   		             PublicationName="";
  		             Edition="";
  		          }
			 }
			 else if(_table[i].getAttribute('id')==id)
			 {
			        if(unselect=="")
			         {
				     document.getElementById(id).className='iconselect';
				     BookAccessionId+=bookAccessionId+"|";
   					 BookTitle+=bookTitle+"|";
   					 BookAccessionNo+=bookAccesionNo+"|";
   					 Author+=author+"|";
   					 PublicationName+=publicationName+"|";
   					 Edition+=edition+"|";
   					 }
			}
		  }
		  else  /* Code For Get the Single Item and make the div for multiple item also without ctrl key*/
		  {
		    var _tempBookAccessionId=BookAccessionId.split("|");
		   if(_tempBookAccessionId.length>2) /* Div For Multiple Item */
		   {
		        if (_table[i].getAttribute('name')==name)
			   {
				         var BookAccessionIdArray=new Array()
						  var BookTitleArray=new Array()
						  var BookAccessionNoArray=new Array()
						  var AuthorArray=new Array()
						  var PublicationNameArray=new Array()
						  var EditionArray=new Array()
						  BookAccessionIdArray=BookAccessionId.split("|");
						  BookTitleArray=BookTitle.split("|");
						  BookAccessionNoArray=BookAccessionNo.split("|");
						  AuthorArray=Author.split("|");
						  PublicationNameArray=PublicationName.split("|");
						  EditionArray=Edition.split("|");
						  var _temp="";
						  for (var i=0;i<BookAccessionIdArray.length-1;i++)
						  {
							 _temp+='<tr><td>'+BookTitleArray[i]+'</td><td>'+BookAccessionNoArray[i]+'</td><td>'+AuthorArray[i]+'</td><td>'+PublicationNameArray[i]+'</td><td>'+EditionArray[i]+'</td></tr>';
							 var div=document.createElement("div");
							 div.id="moving";
							 div.style.position='absolute';
							 div.style.left=""+X+"px";
							 div.style.top=""+Y+"px";
							 div.style.cursor="move";
							 div.innerHTML="<table class='tblist' width='300px' cellpadding='0' cellspacing='0'border='1' >"+_temp+"</table>";
						  }
					 document.body.appendChild(div);
					  From='Drop';
					 document.onmouseup=mouseUpEve;
					 break;
			   }
		   }
		   else if(_tempBookAccessionId.length==0 || _tempBookAccessionId.length==1 || _tempBookAccessionId.length==2) /* Div For Single Item*/
		   {
		           if((_table[i].getAttribute('name')==name) && (_table[i].getAttribute('id')!=id))
			       {
				       var _id=_table[i].getAttribute('id');
				       document.getElementById(_id).className='icon';
    				  
			       }
			       else if (_table[i].getAttribute('name')==name)
			       {
					     document.getElementById(id).className='iconselect';
					     BookAccessionId="";
					     BookTitle="";
					     BookAccessionNo="";
					     Author="";
					     PublicationName="";
					     Edition="";
					     BookTitle+=bookTitle+"|";
					     BookAccessionId+=bookAccessionId+"|";
					     BookAccessionNo+=bookAccesionNo+"|";
					     Author+=author+"|";
					     PublicationName+=publicationName+"|";
					     Edition+=author+"|";
	                     var _temp="";
				 	     _temp+='<tr><td>'+bookTitle+'</td><td>'+bookAccesionNo+'</td><td>'+author+'</td><td>'+publicationName+'</td><td>'+edition+'</td></tr>';
					     var div=document.createElement("div");
					     div.id="moving";
					     div.style.position='absolute';
					     div.style.left=""+X+"px";
					     div.style.top=""+Y+"px";
					     div.style.cursor="move";
					     div.innerHTML="<table class='tblist' width='300px' cellpadding='0' cellspacing='0'border='1' >"+_temp+"</table>";
					     document.body.appendChild(div);
					     From='Drop';
					     document.onmouseup=mouseUpEve;
					      break;
			        }
			   
			 }
		  }
   
	   }
 }
  function stopParentDefault(e)
  {
	  if(e.stopPropogation)
	  {
		   e.stopPropogation();
	  }
	  else
	  {
		  e.cancelBubble=true;
	  }
  }
  function changeDefault()
  {
	             BookAccessionId="";
   		         BookTitle="";
   	 	         BookAccessionNo="";
    	         Author="";
   		         PublicationName="";
  		         Edition=""; 
	 var _table=document.getElementsByTagName('table');
	  for(var i=0;i<_table.length;i++)
	  {
		    if(_table[i].className=='iconselect')
			{
		     _table[i].className='icon';
			}
	   }
	   document.getElementById("checkAllDropedItem").checked=false;
  }
  function unAllocateBooks()
  {
	                      var BookAccessionIdArray=new Array()
						  var BookTitleArray=new Array()
						  var BookAccessionNoArray=new Array()
						  var AuthorArray=new Array()
						  var PublicationNameArray=new Array()
						  var EditionArray=new Array()
						  BookAccessionIdArray=BookAccessionId.split("|");
						  BookTitleArray=BookTitle.split("|");
						  BookAccessionNoArray=BookAccessionNo.split("|");
						  AuthorArray=Author.split("|");
						  PublicationNameArray=PublicationName.split("|");
						  EditionArray=Edition.split("|");
					if(BookAccessionIdArray.length>1)
					{
						  for (var i=0;i<BookAccessionIdArray.length-1;i++)
						  {
					        var where=0;
						    where = document.getElementById("Book").rows.length; 
							var td=document.getElementById("Book").rows[where-1].cells.length;
							if(td==1)
							{
								 //alert("Eneter");
								 document.getElementById("Book").deleteRow(where-1);
							}
							where = document.getElementById("Book").rows.length; 
                            var x=document.getElementById("Book").insertRow(where);
							x.id="bookrow"+where+"";
							x.setAttribute("onmousedown","stopDefault(event);getRowId(this.id,'Book',event);")
							x.setAttribute("onmouseover","cursor(this.id);")
					        var cl= new Array();
							cl[0]=x.insertCell(0);
							cl[1]=x.insertCell(1);
							cl[2]=x.insertCell(2);        
							cl[3]=x.insertCell(3);
							cl[4]=x.insertCell(4);
							cl[5]=x.insertCell(5);
							cl[6]=x.insertCell(6);
							cl[7]=x.insertCell(7);
							cl[0].innerHTML="<input type='checkbox' id='checkBook"+where+"' name='checkBook'/>";
							cl[1].innerHTML="<img src='img/Book-icon.png' alt='' height='20px' width='20px'  id='img"+where+"'/>";
							cl[2].innerHTML="<input type='hidden' name='BookTitle' id='BookTitle"+where+"' value='"+BookTitleArray[i]+"' />"+BookTitleArray[i];
							cl[3].innerHTML="<input type='hidden' id='Bookid"+where+"' name='Bookid' value='' /><input type='hidden' id='BookAccessionId"+where+"' name='BookAccessionId' value='"+BookAccessionIdArray[i]+"'/>";
							cl[4].innerHTML="<input type='hidden' name='DragBookAccessionNo' id='DragBookAccessionNo"+where+"' value='"+BookAccessionNoArray[i]+"' />"+BookAccessionNoArray[i];
							cl[5].innerHTML="<input type='hidden' name='Author' id='Author"+where+"' value='"+AuthorArray[i]+"' />"+AuthorArray[i];
							cl[6].innerHTML="<input type='hidden' name='PublicationName' id='PublicationName"+where+"' value='"+PublicationNameArray[i]+"' />"+PublicationNameArray[i];
							cl[7].innerHTML="<input type='hidden' name='Edition' id='Edition"+where+"' value='"+EditionArray[i]+"'/>"+EditionArray[i]
							
						  }
						  senddata('BookLocationLinking','T=BookLocationLinking_Save&Status=L&BookAccessionId='+BookAccessionId+'&BuildingId='+document.getElementById('DropBuildingId').value+'&FloorId='+document.getElementById('DropFloorId').value+'&RoomId='+document.getElementById('DropRoomId').value+'&AlmirahId='+document.getElementById('AlmirahId').value+'&sectionId='+document.getElementById('SectionId').value+'&searchtype=&val=','Explorer')
					   BookAccessionId="";
  					   BookTitle="";
  					   BookAccessionNo="";
  					   Author="";
 				       PublicationName="";
                       Edition="";
                        document.getElementById("checkAllDropedItem").checked=false;
					}
					else
					{
						 alert("Please select book for unallocate");
					}
  }
  function setAttrib(Query,RecieveId)
  {
	if(document.getElementById('storeAddress'))
	{
		document.getElementById('storeAddress').value+="senddata('BookLocationLinking','"+Query+"','"+RecieveId+"');|";
		document.getElementById('storeQuery').value+=Query+"|"
		document.getElementById('storeReceive').value+=RecieveId+"|"
	}
	var strValue=new Array()
	strValue=document.getElementById('storeAddress').value.split("|");
	strQuery=document.getElementById('storeQuery').value.split("|");
	strRec=document.getElementById('storeReceive').value.split("|");
	if(strValue.length>0)
	{
		for(var i=0;i<strValue.length;i++)
		{
			 if(strValue[i]=="senddata('BookLocationLinking','"+Query+"','"+RecieveId+"');")
			 {
				 document.getElementById("btnBack").setAttribute("onclick",strValue[i-2]+'setAttrib("'+strQuery[i-2]+'","'+strRec[i-2]+'")');
				 document.getElementById("btnForward").setAttribute("onclick",strValue[i]);
			 }
		}
	}
  }
  function changeSpanName(val)
{
   
   var ele=document.getElementById('spanName');
   if (val==1)
   {
      ele.innerHTML="Enter Book Title";
   }
  else if(val==2) 
   {
        
     ele.innerHTML="Enter Author Name";
   }
  else if(val==3)
   {
	ele.innerHTML="Enter Edition ";
   }
  else if(val==4)
	{
	ele.innerHTML="Enter Publication Name";
	}
  else if(val==5)
	{
	ele.innerHTML="Enter Accession No."; 	 
	}
  
}
function goFilter()
{
   senddata('BookLocationLinking','T=Filter&searchtype='+document.getElementById('searchType').value+'&val='+document.getElementById('val').value,'searchDiv');
}


function checkedAll()
{
    var checkBook=document.getElementsByName('checkBook');
	var _AccessionHID=document.getElementsByName("BookAccessionId");
	if(document.getElementById('checkAll').checked==true)
	{	
		for(var i=0; i<checkBook.length;i++)
		{
		   document.getElementsByName('checkBook')[i].checked=true;
		}
	}
	else
	{
	   for(var i=0; i<checkBook.length;i++)
		{
		   document.getElementsByName('checkBook')[i].checked=false;
		   _AccessionHID[i].value="";
		}
	}
}
function stateChanged()
{
    if (xmlhttp.readyState==4)
	{
	   document.getElementById(receiveid).innerHTML=xmlhttp.responseText;
	}
	else
	{
		document.getElementById(receiveid).innerHTML="<div align='center'><img src='images/loading.gif' /></div>";
	}
}
function getValue()
{
   var _bookId="";
   var _accessionId="";
   var _tempBookId="";
   var _tempAcessionId="";
   var _eleBookid=document.getElementsByName('Bookid');
   var _eleBookAccessionId=document.getElementsByName('BookAccessionId');
   var _eleCheck=document.getElementsByName('checkBook');
   for(var i=0;i<_eleBookid.length;i++)
   {
         if(_eleCheck[i].checked==true)
		 {
        _bookId+=_eleBookid[i].value+"|";
		_accessionId+=_eleBookAccessionId[i].value+"|";
		 }
   }
   return{_tempBookId:_bookId,_tempAcessionId:_accessionId}
}
function add(){senddata('BookLocationLinking','T=A','pagedata');}
function save(){if(validate()){var get=getValue();if(get._tempBookId!=""){senddata('BookLocationLinking','T=BookLocationLinking_Save&Status=U&BookId='+get._tempBookId+'&BookAccessionId='+get._tempAcessionId+'&BuildingId='+document.getElementById('BuildingId').value+'&FloorId='+document.getElementById('FloorId').value+'&RoomId='+document.getElementById('RoomId').value+'&AlmirahId='+document.getElementById('AlmirahId').value+'&sectionId='+document.getElementById('SectionId').value+'&searchtype='+document.getElementById('searchType').value+'&val='+document.getElementById('val').value,'searchDiv');}else{alert('Please select a book for move.')}}}
function getValueofDropItem(tableName,RowName)
   {
       var value="";
       var tableEle=document.getElementById(tableName).getElementsByTagName('input');
	   for(var i=0;i<tableEle.length;i++)
	   {
	      if(tableEle[i].name==RowName)
		  {
		     value+=tableEle[i].value+"|";
		  }
	   }
	   return value;
   }
   
//   function clearDestinationId()
//   {
//     RowId="";
//   }
//	function Show(id)
//	{
//	   document.getElementById(id).src='img/nolines_plus.gif';
//	   document.getElementById(id).setAttribute('onclick','Hide(this.id);');
//	   var ele=document.getElementsByName(id);
//	   for(var i=0;i<ele.length;i++)
//	   {
//	       ele[i].style.display='none';
//	   }
//	}
	function ShowHide(id,base,imageid)
	{         
	          var _tagName=document.getElementsByTagName('tr');
			  for (var i=0;i<_tagName.length;i++)
			  {
			     
			          if(_tagName[i].getAttribute('name')==id || _tagName[i].getAttribute('title')==id )
					  {
					  
						var ele=_tagName[i];
						if(_tagName[i].className!=null)
						{
						  	  	   
							if (_tagName[i].className=='static')
								{
								
								_tagName[i].className='none';
								 document.getElementById(imageid).src='img/nolines_plus.gif';
								}
							else 
								{
								   if(_tagName[i].getAttribute('master')==base)
								   {
								  
								   }
								   else
								   {
								      _tagName[i].className='static';
									   document.getElementById(imageid).src='img/nolines_minus.gif'
								   }
								 				 
								}
						 }
						 else
						 {
						        _tagName[i].setAttribute('className','none');
								//document.getElementById(id).src='img/nolines_plus.gif';
						 }
					  }
			  }
				 
	}
	

  
